package com.example.livestockbreedingapplication.slice;

import com.example.livestockbreedingapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;

public class SettingSlice extends AbilitySlice implements Component.ClickedListener {
    private Component componentLayout;
    private AbilitySlice slice = this;
    private TabList tabList;
    private String[] str = {"系统设置", "运行设置","曲线设置","风机设置","光照设置","报警设置","二氧化碳设置","氨气设置","湿度设置","时间设置","返回主页"};
    private TabListSelect listSelect = new TabListSelect();
    ComponentContainer container;
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_navigation_bar);

        container = (ComponentContainer) findComponentById(ResourceTable.Id_tab_container);
        tabList = (TabList) findComponentById(ResourceTable.Id_tab_list_bottom);

        if (tabList.getTabCount()<str.length){
            for (int i = 0; i < str.length; i++) {
                TabList.Tab tab = tabList.new Tab(getContext());
                tab.setText(str[i]);

                tabList.addTab(tab);
            }
        }

        tabList.setFixedMode(true);

        tabList.addTabSelectedListener(listSelect);
        //默认第一个被选中
        tabList.getTabAt(2).select();
    }

    @Override
    public void onClick(Component component) {

    }

    class TabListSelect implements TabList.TabSelectedListener{
        @Override
        public void onSelected(TabList.Tab tab) {
            // 当某个Tab从未选中状态变为选中状态时的回调

            if (tab.getText().equals("系统设置")){
                container.removeAllComponents();
                componentLayout = LayoutScatter.getInstance(slice).parse(ResourceTable.Layout_ability_setting_system,null,false);
                container.addComponent(componentLayout);
            }else if (tab.getText().equals("运行设置")){
                container.removeAllComponents();
                componentLayout = LayoutScatter.getInstance(slice).parse(ResourceTable.Layout_ability_setting_operation,null,false);
                container.addComponent(componentLayout);
            }else if (tab.getText().equals("风机设置")){
                container.removeAllComponents();
                componentLayout = LayoutScatter.getInstance(slice).parse(ResourceTable.Layout_ability_setting_fengji,null,false);
                container.addComponent(componentLayout);
            }else if (tab.getText().equals("报警设置")){
                container.removeAllComponents();
                componentLayout = LayoutScatter.getInstance(slice).parse(ResourceTable.Layout_ability_setting_baojing,null,false);
                container.addComponent(componentLayout);
            }else if (tab.getText().equals("光照设置")){
                container.removeAllComponents();
                componentLayout = LayoutScatter.getInstance(slice).parse(ResourceTable.Layout_ability_setting_guangzhao,null,false);
                container.addComponent(componentLayout);
            }else if (tab.getText().equals("时间设置")){
                container.removeAllComponents();
                componentLayout = LayoutScatter.getInstance(slice).parse(ResourceTable.Layout_ability_setting_date,null,false);
                container.addComponent(componentLayout);
            }else if (tab.getText().equals("氨气设置")){
                container.removeAllComponents();
                componentLayout = LayoutScatter.getInstance(slice).parse(ResourceTable.Layout_ability_setting_nh3,null,false);
                container.addComponent(componentLayout);
            }else if (tab.getText().equals("二氧化碳设置")){
                container.removeAllComponents();
                componentLayout = LayoutScatter.getInstance(slice).parse(ResourceTable.Layout_ability_setting_co2,null,false);
                container.addComponent(componentLayout);
            }else if (tab.getText().equals("湿度设置")){
                container.removeAllComponents();
                componentLayout = LayoutScatter.getInstance(slice).parse(ResourceTable.Layout_ability_setting_humid,null,false);
                container.addComponent(componentLayout);
            }else if (tab.getText().equals("曲线设置")){
                container.removeAllComponents();
                componentLayout = LayoutScatter.getInstance(slice).parse(ResourceTable.Layout_ability_curve,null,false);
                container.addComponent(componentLayout);
            }
            else if (tab.getText().equals("返回主页")){

                terminate();
            }


        }

        @Override
        public void onUnselected(TabList.Tab tab) {

        }

        @Override
        public void onReselected(TabList.Tab tab) {

        }
    }

    @Override
    protected void onActive() {
        super.onActive();
    }


    @Override
    protected void onForeground(Intent intent) {
        super.onForeground(intent);

    }

    @Override
    protected void onBackground() {
        super.onBackground();

    }

    @Override
    protected void onStop() {
        super.onStop();

    }
}
